package com.example.travel_front.Adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.travel_front.Model.HourlyForecast;
import com.example.travel_front.R;

import java.util.List;

public class HourlyForecastAdapter extends RecyclerView.Adapter<HourlyForecastAdapter.ViewHolder> {

    private final List<HourlyForecast> forecastList;

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView timeTextView;
        public ImageView weatherIconImageView;
        public TextView temperatureTextView;

        public ViewHolder(View itemView) {
            super(itemView);
            timeTextView = itemView.findViewById(R.id.timeTextView);
            weatherIconImageView = itemView.findViewById(R.id.weatherIconImageView);
            temperatureTextView = itemView.findViewById(R.id.temperatureTextView);
        }
    }

    public HourlyForecastAdapter(List<HourlyForecast> forecastList) {
        this.forecastList = forecastList;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_hourly_forecast, parent, false);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        HourlyForecast forecast = forecastList.get(position);
        holder.timeTextView.setText(forecast.getTime());
        holder.weatherIconImageView.setImageResource(forecast.getWeatherIconResId());
        holder.temperatureTextView.setText(forecast.getTemperature());
    }
    @Override
    public int getItemCount() {
        return forecastList.size();
    }
}

